﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using Entities;
using Data;
namespace Business
{
    public class BaoCaoCongNoService
    {
        public static bool Exists(DateTime thang)
        {
            return BaoCaoCongNoRepository.Exists(thang);
        }
        public static BaoCaoCongNoDTO GetBaoCaoCongNoByThang(DateTime thang)
        {
            return BaoCaoCongNoRepository.GetBaoCaoCongNoByThang(thang);
        }
        public static int GetCurrentID()
        {
            return BaoCaoCongNoRepository.GetCurrentID();
        }
        public static void Insert(BaoCaoCongNoDTO baoCaoCongNo)
        {
            BaoCaoCongNoRepository.Insert(baoCaoCongNo);
        }

        public static DataTable LapBaoCao(DateTime thang)
        {
            DataTable kq = new DataTable();
            BaoCaoCongNoDTO baoCaoCongNo = BaoCaoCongNoRepository.GetBaoCaoCongNoByThang(thang);
            if (baoCaoCongNo == null)
                return null;
            List<ChiTietBaoCaoCongNoDTO> listChiTiet = ChiTietBaoCaoCongNoRepository.GetChiTietBaoCaoList(baoCaoCongNo.MaBaoCaoCongNo);
            kq =ConvertTo.DataTable(listChiTiet);
            kq.Columns.Add("HoTen");
            for (int i = 0; i < kq.Rows.Count; i++)
            {
                kq.Rows[i]["HoTen"] = KhachHangService.GetKhachHangByMaKhachHang((int)kq.Rows[i]["MaKhachHang"]).HoTen;
            }
            return kq;
        }
    }
}
